<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>打印测完</title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <link href="" rel="stylesheet">
    <style>
        #oDiv2 div {
            width: 100px;
            height: 100px;
            border: 1px solid #c50000;
        }
    </style>
</head>

<body>
    <div>aaa</div>
    <div id='oDiv2'>
        <div>bbb</div>
    </div>
    <div>ccc</div>
    <input type="button" value="打印" id="js_print" />
    <img src=""
        class="search-box-icon" alt="">
    <script>
        var oPrintBtn = document.getElementById("js_print");
        var oDiv2 = document.getElementById("oDiv2");
        oPrintBtn.onclick = function () {
            var oPop = window.open('', 'oPop');
            var str = '<!DOCTYPE html>'
            str += '<html>'
            str += '<head>'
            str += '<meta charset="utf-8">'
            str += '<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">'
            str += '<style>';
            str += '#oDiv2 div{width: 100px;height: 100px;border:1px solid #c50000;}';
            str += '</style>';
            str += '</head>'
            str += '<body>'
            str += "<div id='oDiv2'><div>bbb</div></div>";
            str += '</body>'
            str += '</html>'

            oPop.document.write(str);
            oPop.print();
            oPop.close();
        }
    </script>
    <span id='div1'>把要打印的内容放这里</span>

    <p>所有内容</p>

    <div id="div2">div2的内容</div>

    <a href="javascript:printme()" rel="external nofollow" target="_self">打印</a>

    <script language="javascript">
        function
        printme()

        {
            document.body.innerHTML = document.getElementById('div1').innerHTML + '<br/>' + document.getElementById(
                'div2').innerHTML;

            window.print();

        }
    </script>
</body>

</html>